package fy.uap.dao;

import com.seeyon.ctp.util.UUIDLong;
import fy.config.DBConfigBean;
import fy.config.FyConfig;
import fy.uap.bean.ProviderImportFormBean;
import fy.uap.bean.RangeBean;
import fy.util.DBUtil;
import fy.util.MyUtil;
import java.io.PrintStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class SrmProviderImportFormDao {
	private static Log log = LogFactory.getLog(SrmProviderImportFormDao.class);
	private String uapUserID = "0001AA10000000009KX7";
	private ProviderImportFormBean providerImportFormBean;
	private List<String> companyList;
	private List<String> supplyRangeList;
	private List<RangeBean> failRangeList;
	private List<RangeBean> unchangingRangeList;
	private List<RangeBean> successRangeList;
	private boolean writeToErpSuccess = false;
	private boolean writeAptitudeSuccess;
	private String uapAccountID = null;

	public List<RangeBean> getFailRangeList() {
		return this.failRangeList;
	}

	public List<RangeBean> getUnchangingRangeList() {
		return this.unchangingRangeList;
	}

	public List<RangeBean> getSuccessRangeList() {
		return this.successRangeList;
	}

	public void setProviderImportFormBean(ProviderImportFormBean providerImportFormBean) {
		this.providerImportFormBean = providerImportFormBean;
	}

	public boolean save() {
		String UPDATE_VENDOR_INVCLASS_STATE_CHANGE = "update fy_supplier_vendor_invclass set cvendorclass=?, changeTrace=?, denddate=? where pk_veninv=? and cvendorclass<>'3'";
		String updateSuppliserBankInfo = "update fy_supplier_vendor_invclass i set i.bankaccountname=?,i.bankcode = ?, i.bank = ?,i.bankaccount = ?,i.currency = ? where i.pk_vendor = ( select v.pk_vendor from fy_supplier_vendor v where v.cvencode = ? and nvl(v.dr,0) = 0) and i.pk_corp=?";

		String insertSuppliserVendor = "insert into fy_supplier_vendor (pk_vendor,cvencode,cvenname,ctrade,cvenregcode,dorf,cqualitycond,cvenbank,cvenaccount,cmoneytype,cpurbillcode,couttype,cvenaddress,cvenpostcode, cvenperson, cvenphone,cvenfax,cvenemail,cveniaddress,ccuspaycond,ccontent,cycle,ccreateperson,dvendevdate, ts, creater,cVenBankMemo,cvenfygl) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";

		String updateSuppliserVendor = "update fy_supplier_vendor set cvenname=?,ctrade=?,cvenregcode=?,dorf=?,cqualitycond=?,cvenbank=?,cvenaccount=?,cmoneytype=?,cpurbillcode=?,couttype=?,cvenaddress=?,cvenpostcode=?, cvenperson=?, cvenphone=?,cvenfax=?,cvenemail=?,cveniaddress=?,ccuspaycond=?,ccontent=?,cycle=?,ccreateperson=?,dvendevdate=?, ts=?,cVenBankMemo=?,cvenfygl=? where cvencode=? and (dr='0' or dr is null) ";

		String insertVendorInvcalss = "insert into fy_supplier_vendor_invclass (pk_veninv, pk_corp, pk_invclass, cvendorclass, ts, pk_vendor, dvendevdate, changeTrace,creater,bankaccountname,bankcode, bank,bankaccount,currency) values ( ?, ?, ?, ?, ?, ?, ?, ?, ?,?,?,?,?,?)";

		String SELECT_VENDOR_INVCLASS = "select t.pk_vendor, trim(t.pk_corp), t.pk_invclass, t.cvendorclass, t.pk_veninv,t.denddate from fy_supplier_vendor_invclass t, fy_supplier_vendor v where (t.dr='0' or t.dr is null) and v.pk_vendor = t.pk_vendor and v.cvencode = ? ";

		String insertVendorInvcalssIfNotBlacklist = "insert into fy_supplier_vendor_invclass (pk_veninv, pk_corp, pk_invclass, cvendorclass, ts, pk_vendor, dvendevdate, changeTrace, creater) select ?, ?, ?, ?, ?, ?, ?, ?, ? from dual where not exists ( select * from fy_supplier_vendor_invclass where pk_corp=? and pk_invclass=? and pk_vendor=? and (dr='0' or dr is null) and ( cvendorclass = '3' or cvendorclass = '0'))";
		String insertLog = "insert into fy_supplier_vendor_history(pk_venhis, pk_vendor, pk_corp, pk_invclass, changetype, changememo, changevouch, changecode, changer, ts, changedate,creater) values ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )";

		String insertLogIfNotBlacklist = "insert into fy_supplier_vendor_history(pk_venhis, pk_vendor, pk_corp, pk_invclass, changetype, changememo, changevouch, changecode, changer, ts, changedate, creater) select ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? from dual where not exists (select * from fy_supplier_vendor_invclass where pk_corp=? and pk_invclass=? and pk_vendor=? and (dr='0' or dr is null) and cvendorclass = '3')";

		String ERPUADATE = "update apps.FYG_PO_UAP_VENDORS@" + FyConfig.getERP_DB_CONFIG().getDblink()
				+ " av set (av.vendors_name, av.flag,av.zt,av.disable_date) = (select v.cvenname cvenname,      decode(sign(to_date(vi.denddate, 'YYYY-MM-DD') - sysdate),   -1,   'N',   decode(vi.cvendorclass, '3', 'N', 'Y')) flag   ,decode(sign(to_date(vi.denddate, 'YYYY-MM-DD') - sysdate),-1,'停用',   decode(vi.cvendorclass,          '1',          '合格',          '2',          '潜在',          '3',          '黑名单',          vi.cvendorclass)) zt,      to_date(vi.denddate, 'YYYY-MM-DD') disable_date from fy_supplier_vendor_invclass vi left join fy_supplier_vendor v on vi.pk_vendor = v.pk_vendor left join bd_corp c on vi.pk_corp = c.pk_corp left join fy_supplier_invclass i on vi.pk_invclass =       i.pk_invclass          where v.cvencode = ? and (vi.dr is null or vi.dr = 0) and av.vendors_num =v.cvencode and av.syb=c.unitname and av.uaplb = i.cinvclasscode )  where av.vendors_num =  ? and exists (select * from fy_supplier_vendor_invclass vi left join fy_supplier_vendor v on vi.pk_vendor = v.pk_vendor left join bd_corp c on vi.pk_corp = c.pk_corp left join fy_supplier_invclass i on vi.pk_invclass =       i.pk_invclass          where v.cvencode = ? and (vi.dr is null or vi.dr = 0) and av.vendors_num =v.cvencode and av.syb=c.unitname and av.uaplb = i.cinvclasscode) ";

		String ERPINSERTSQL = "insert into apps.FYG_PO_UAP_VENDORS@" + FyConfig.getERP_DB_CONFIG().getDblink()
				+ "(VENDORS_NUM, VENDORS_NAME, SYB, UAPLB, ZT, disable_date,flag) select * from (select v.cvencode cvencode,  v.cvenname cvenname,  c.unitname unitname,  i.cinvclasscode cinvclasscode,  decode(sign(to_date(vi.denddate, 'YYYY-MM-DD') - sysdate),-1,'停用',decode(vi.cvendorclass,'1','合格',  '2',  '潜在',  '3',  '黑名单',  vi.cvendorclass)) zt,  to_date(vi.denddate, 'YYYY-MM-DD') disable_date,  decode(sign(to_date(vi.denddate, 'YYYY-MM-DD') - sysdate),-1,'N',decode(vi.cvendorclass,  '3',  'N',  'Y')) flag    from fy_supplier_vendor_invclass vi    left join fy_supplier_vendor v on vi.pk_vendor = v.pk_vendor    left join bd_corp c on vi.pk_corp = c.pk_corp    left join fy_supplier_invclass i on vi.pk_invclass = i.pk_invclass where v.cvencode=? and (vi.dr is null or vi.dr = 0) ) t where not exists ( select *    from apps.FYG_PO_UAP_VENDORS@"
				+ FyConfig.getERP_DB_CONFIG().getDblink()
				+ " e where t.cvencode = e.VENDORS_NUM and e.SYB = t.unitname and e.UAPLB=t.cinvclasscode and t.zt = e.zt and (t.disable_date is null and e.disable_date is null or t.disable_date = e.disable_date) ) ";

		boolean success = false;
		Connection conn = null;
		PreparedStatement pst = null;
		PreparedStatement pst1 = null;
		PreparedStatement pst2 = null;
		ResultSet rs = null;
		ContentMapping contentMapping = new ContentMapping();

		log.info("导入制造部名称：" + this.providerImportFormBean.getSupplyCompany());
		String[] strs1 = this.providerImportFormBean.getSupplyCompany().split(";");
		for (int temp = 0; strs1.length > temp; temp++) {
			log.info("所属制造部：" + strs1[temp]);
		}
		String[] strs2 = (String[]) this.companyList.toArray(new String[this.companyList.size()]);
		for (int temp = 0; strs2.length > temp; temp++) {
			log.info("共享制造部：" + strs2[temp]);
		}
		Set<String> set = new TreeSet();
		set.addAll(Arrays.asList(strs1));
		set.addAll(Arrays.asList(strs2));
		String[] strs = (String[]) set.toArray(new String[set.size()]);
		for (int temp = 0; strs.length > temp; temp++) {
			log.info("所有制造部：" + strs[temp]);
		}
		try {
			conn = DBUtil.connect(FyConfig.getUAP_DB_CONFIG());
			long changeTrace = UUIDLong.longUUID();
			pst = conn.prepareStatement("select cvenname from fy_supplier_vendor where cvencode=? and  nvl(dr,0) = 0");
			pst.setString(1, this.providerImportFormBean.getProviderCode());
			rs = pst.executeQuery();

			int providerIsExist = -1;
			if (rs.next()) {
				if (this.providerImportFormBean.getProviderName().equals(rs.getString(1))) {
					providerIsExist = 1;
				}
			} else {
				providerIsExist = 0;
			}
			log.info("是否存在：" + providerIsExist);

			conn.setAutoCommit(false);
			if (providerIsExist == 0) {
				String Cmoneytype = this.providerImportFormBean.getCmoneytype();
				String Couttype = this.providerImportFormBean.getCouttype();
				log.info("#########" + Cmoneytype + Couttype);

				pst = conn.prepareStatement(insertSuppliserVendor);
				String pk_vendor = String.valueOf(UUIDLong.longUUID());
				pst.setString(1, pk_vendor);
				pst.setString(2, this.providerImportFormBean.getProviderCode());
				pst.setString(3, this.providerImportFormBean.getProviderName());
				pst.setString(4, this.providerImportFormBean.getCompanyType());
				pst.setString(5, this.providerImportFormBean.getTaxRegister());
				pst.setString(6, this.providerImportFormBean.getProperty());
				pst.setString(7, this.providerImportFormBean.getQualitySystem());
				pst.setString(8, this.providerImportFormBean.getCvenbank());
				pst.setString(9, this.providerImportFormBean.getBankAccount());
				pst.setString(10, Cmoneytype);
				pst.setString(11, this.providerImportFormBean.getCpurbillcode());
				pst.setString(12, Couttype);
				pst.setString(13, this.providerImportFormBean.getSupplyAddress());
				pst.setString(14, this.providerImportFormBean.getPostCode());
				pst.setString(15, this.providerImportFormBean.getLinkman());
				pst.setString(16, this.providerImportFormBean.getTel());
				pst.setString(17, this.providerImportFormBean.getFax());
				pst.setString(18, this.providerImportFormBean.getEmail());
				pst.setString(19, this.providerImportFormBean.getAddress());
				pst.setString(20, this.providerImportFormBean.getCcuspaycond());
				pst.setString(21, this.providerImportFormBean.getCcontent());
				pst.setString(22, MyUtil.getLimitLengthString(this.providerImportFormBean.getSupplyCycle(), 20, "…"));
				pst.setString(23, this.uapUserID);
				pst.setString(24, MyUtil.getTodayDateStr());
				pst.setString(25, this.providerImportFormBean.getApplicationTime());
				pst.setString(26, this.providerImportFormBean.getMemberCode());
				pst.setString(27, this.providerImportFormBean.getcVenBankMemo());
				pst.setString(28, this.providerImportFormBean.getCvenfygl());
				pst.executeUpdate();
				DBUtil.close(pst);
				log.info("$$" + pk_vendor + this.providerImportFormBean.getProviderCode()
						+ this.providerImportFormBean.getProviderName() + this.providerImportFormBean.getCompanyType()
						+ this.providerImportFormBean.getTaxRegister() + this.providerImportFormBean.getProperty()
						+ this.providerImportFormBean.getQualitySystem() + this.providerImportFormBean.getCvenbank()
						+ this.providerImportFormBean.getBankAccount() + Cmoneytype
						+ this.providerImportFormBean.getCpurbillcode() + Couttype
						+ this.providerImportFormBean.getSupplyAddress() + this.providerImportFormBean.getPostCode()
						+ this.providerImportFormBean.getLinkman() + this.providerImportFormBean.getTel()
						+ this.providerImportFormBean.getFax() + this.providerImportFormBean.getEmail()
						+ this.providerImportFormBean.getAddress() + this.providerImportFormBean.getCcuspaycond()
						+ this.providerImportFormBean.getCcontent()
						+ MyUtil.getLimitLengthString(this.providerImportFormBean.getSupplyCycle(), 20, "…")
						+ this.uapUserID + MyUtil.getTodayDateStr() + this.providerImportFormBean.getApplicationTime()
						+ this.providerImportFormBean.getMemberCode() + this.providerImportFormBean.getcVenBankMemo()
						+ this.providerImportFormBean.getCvenfygl());

				pst = conn.prepareStatement(insertVendorInvcalss);

				pst1 = conn.prepareStatement(insertLog);
				for (int i = 0; i < strs.length; i++) {
					String companyName = strs[i];
					if (companyName.equals("福耀玻璃工业集团股份有限公司（万达）")) {
						this.uapAccountID = "1025";
					} else {
						this.uapAccountID = contentMapping.getUapAccountID(companyName);
					}
					log.info("公司编码pk_corp：" + this.uapAccountID + "次数" + i);
					log.info("供货范围size：" + this.providerImportFormBean.getSupplyRangeList().size());
					for (int y = 0; y < this.providerImportFormBean.getSupplyRangeList().size(); y++) {
						String supplyRange = contentMapping.querypk_invclassTypeSelectOption(
								(String) this.providerImportFormBean.getSupplyRangeList().get(y));
						log.info("供货范围size：" + this.providerImportFormBean.getSupplyRangeList().size()
								+ "供货范围supplyRange1：" + supplyRange);
						if (supplyRange.equals("100200100000000004MZ")) {
							supplyRange = "10020010000000002FZB";
						}
						log.info("供货范围supplyRange2：" + supplyRange);
						String pk_veninv = String.valueOf(UUIDLong.longUUID());
						log.info("pk_veninv:" + pk_veninv + '\n' + "uapAccountID" + this.uapAccountID + '\n'
								+ "supplyRange" + supplyRange + '\n'
								+ "this.providerImportFormBean.getApplicationTime()"
								+ this.providerImportFormBean.getApplicationTime() + '\n' + "pk_vendor" + pk_vendor
								+ '\n' + "MyUtil.getTodayDateStr()" + MyUtil.getTodayDateStr() + '\n' + "changeTrace"
								+ changeTrace + '\n' + " providerImportFormBean.getMemberCode()"
								+ this.providerImportFormBean.getMemberCode() + '\n'
								+ "providerImportFormBean.getBankAccountName()"
								+ this.providerImportFormBean.getBankAccountName() + '\n'
								+ "providerImportFormBean.getBankAccountName()"
								+ this.providerImportFormBean.getBankAccountName() + '\n'
								+ "providerImportFormBean.getBankCode()" + this.providerImportFormBean.getBankCode()
								+ '\n' + "providerImportFormBean.getcVenBankMemo()"
								+ this.providerImportFormBean.getcVenBankMemo() + '\n' + "Cmoneytype" + Cmoneytype);
						pst.setString(1, pk_veninv);
						pst.setString(2, this.uapAccountID);
						pst.setString(3, supplyRange);

						pst.setString(4, "2");
						pst.setString(5, this.providerImportFormBean.getApplicationTime());
						pst.setString(6, pk_vendor);
						pst.setString(7, MyUtil.getTodayDateStr());
						pst.setLong(8, changeTrace);
						pst.setString(9, this.providerImportFormBean.getMemberCode());
						pst.setString(10, this.providerImportFormBean.getBankAccountName());
						pst.setString(11, this.providerImportFormBean.getBankCode());
						pst.setString(12, this.providerImportFormBean.getcVenBankMemo());
						pst.setString(13, this.providerImportFormBean.getBankAccount());
						pst.setString(14, Cmoneytype);

						writeLog(pst1, pk_vendor, this.uapAccountID, supplyRange, "新增");
					}
					pst.addBatch();
				}
				pst.executeBatch();
				pst1.executeBatch();
				success = true;
			} else if (providerIsExist == 1) {
				pst = conn.prepareStatement(SELECT_VENDOR_INVCLASS);
				pst.setString(1, this.providerImportFormBean.getProviderCode());
				rs = pst.executeQuery();
				String pk_vendor = null;
				List<SrmSupplyTypeBean> supplyTypeBeans = new ArrayList();
				while (rs.next()) {
					if (pk_vendor == null) {
						pk_vendor = rs.getString(1);
					}
					SrmSupplyTypeBean bean = new SrmSupplyTypeBean();
					bean.setPk_corp(rs.getString(2));
					bean.setPk_invclass(rs.getString(3));
					bean.setCvendorclass(rs.getString(4));
					bean.setPk_veninv(rs.getString(5));
					bean.setDenddate(rs.getString(6));
					supplyTypeBeans.add(bean);
					bean = null;
				}
				DBUtil.close(rs, pst);
				if (pk_vendor == null) {
					pst = conn.prepareStatement(
							"select v.pk_vendor from fy_supplier_vendor v where v.cvencode=?  and nvl(v.dr,0) = 0");
					pst.setString(1, this.providerImportFormBean.getProviderCode());
					rs = pst.executeQuery();
					while (rs.next()) {
						pk_vendor = rs.getString(1);
					}
				}
				DBUtil.close(rs, pst);

				pst = conn.prepareStatement(insertVendorInvcalssIfNotBlacklist);

				pst1 = conn.prepareStatement(insertLogIfNotBlacklist);

				pst2 = conn.prepareStatement(UPDATE_VENDOR_INVCLASS_STATE_CHANGE);

				String operate = this.providerImportFormBean.getOption();
				log.info("operate:" + operate);

				String state = "潜在".equals(operate) ? "2" : "1";
				for (int i = 0; i < strs.length; i++) {
					String companyName = strs[i];
					if (companyName.equals("福耀玻璃工业集团股份有限公司（万达）")) {
						this.uapAccountID = "1025";
					} else {
						this.uapAccountID = contentMapping.getUapAccountID(companyName);
					}
					log.info("this.providerImportFormBean.getSupplyRangeList().size():"
							+ this.providerImportFormBean.getSupplyRangeList().size());
					for (int y = 0; y < this.providerImportFormBean.getSupplyRangeList().size(); y++) {
						String supplyRange = contentMapping.querypk_invclassTypeSelectOption(
								(String) this.providerImportFormBean.getSupplyRangeList().get(y));
						if (supplyRange.equals("100200100000000004MZ")) {
							supplyRange = "10020010000000002FZB";
						}
						SrmSupplyTypeBean SrmSupplyTypeBean = null;
						if ((SrmSupplyTypeBean = typeIsExist(this.uapAccountID, supplyRange,
								supplyTypeBeans)) == null) {
							if ("潜在".equals(this.providerImportFormBean.getOption())) {
								String pk_veninv = String.valueOf(UUIDLong.longUUID());
								pst.setString(1, pk_veninv);
								pst.setString(2, this.uapAccountID);
								pst.setString(3, supplyRange);
								pst.setString(4, state);
								pst.setString(5, this.providerImportFormBean.getApplicationTime());
								pst.setString(6, pk_vendor);
								pst.setString(7, MyUtil.getTodayDateStr());
								pst.setLong(8, changeTrace);
								pst.setString(9, this.providerImportFormBean.getMemberCode());
								pst.setString(10, this.uapAccountID);
								pst.setString(11, supplyRange);
								pst.setString(12, pk_vendor);
								log.info("!!!" + strs[i] + companyName + this.uapAccountID + supplyRange);
								pst.addBatch();
								writeLogIfPrividerExist(pst1, pk_vendor, this.uapAccountID, supplyRange, operate);
							}
						} else {
							if (!"3".equals(SrmSupplyTypeBean.getCvendorclass())) {
								if ((state.equals(SrmSupplyTypeBean.getCvendorclass()))
										|| ("1".equals(SrmSupplyTypeBean.getCvendorclass()))) {
									if ((SrmSupplyTypeBean.getDenddate() != null)
											&& (!"".equals(SrmSupplyTypeBean.getDenddate()))) {
										if (MyUtil.later(SrmSupplyTypeBean.getDenddate(), "00:00:00",
												MyUtil.getTodayDateStr(), "00:00:00")) {
										}
									}
								} else {
									pst2.setString(1, state);
									pst2.setLong(2, changeTrace);
									pst2.setString(3, "");

									pst2.setString(4, SrmSupplyTypeBean.getPk_veninv());
									pst2.addBatch();

									writeLogIfPrividerExist(pst1, pk_vendor, this.uapAccountID, supplyRange, operate);
									continue;
								}
							}
							if (this.unchangingRangeList == null) {
								this.unchangingRangeList = new ArrayList();
							}
							this.unchangingRangeList.add(new RangeBean(this.uapAccountID, supplyRange));
						}
					}
				}
				pst.executeBatch();
				pst2.executeBatch();
				pst1.executeBatch();
			} else {
				System.out.println("无法确认供应商导入操作,供应商导入表单据编号：" + this.providerImportFormBean.getNumber());
				return false;
			}
			DBUtil.close(rs, pst);

			pst = conn.prepareStatement(ERPUADATE);
			pst.setString(1, this.providerImportFormBean.getProviderCode());
			pst.setString(2, this.providerImportFormBean.getProviderCode());
			pst.setString(3, this.providerImportFormBean.getProviderCode());

			pst.execute();

			pst = conn.prepareStatement(ERPINSERTSQL);
			pst.setString(1, this.providerImportFormBean.getProviderCode());
			pst.execute();
			conn.commit();
			DBUtil.setAutoCommit(conn, true);
			writeToErpSuccess = success = true;
			pst = conn.prepareStatement(
					"select i.pk_corp, i.pk_invclass, c.unitname, si.cinvclasscode, v.cvencode, i.cvendorclass, v.cvenname from fy_supplier_vendor_invclass i left join bd_corp c on i.pk_corp = c.pk_corp left join fy_supplier_invclass si on si.pk_invclass = i.pk_invclass left join fy_supplier_vendor v on v.pk_vendor = i.pk_vendor where i.changeTrace= ?");
			pst.setLong(1, changeTrace);
			rs = pst.executeQuery();
			while (rs.next()) {
				if (this.successRangeList == null) {
					this.successRangeList = new ArrayList();
				}
				this.successRangeList.add(new RangeBean(rs.getString(1), rs.getString(2), rs.getString(3),
						rs.getString(5), rs.getString(4), rs.getString(6), rs.getString(7)));
			}
			this.writeAptitudeSuccess = true;

			log.info("success");
		} catch (Exception e) {
			success = false;
			DBUtil.rollback(conn);
			e.printStackTrace();
			log.info(e.fillInStackTrace() + "供应商导入审批数据导入UPA异常");
		} finally {
			DBUtil.setAutoCommit(conn, true);
			DBUtil.close(pst2);
			DBUtil.close(pst1);
			DBUtil.close(rs, pst, conn);
		}
		return success;
	}

	public boolean isWriteAptitudeSuccess() {
		return this.writeAptitudeSuccess;
	}

	private void writeLog(PreparedStatement pst1, String pk_vendor, String uapAccountID, String supplyRange,
			String operate) throws SQLException {
		pst1.setString(1, String.valueOf(UUIDLong.longUUID()));
		pst1.setString(2, pk_vendor);
		pst1.setString(3, uapAccountID);
		pst1.setString(4, supplyRange);
		pst1.setString(5, operate);
		pst1.setString(6, this.providerImportFormBean.getReason());
		pst1.setString(7, "OA供应商导入批准表");
		pst1.setString(8, this.providerImportFormBean.getNumber());
		pst1.setString(9, this.uapUserID);
		pst1.setString(10, MyUtil.getNowStr());
		pst1.setString(11, MyUtil.getTodayDateStr());
		pst1.setString(12, this.providerImportFormBean.getMemberCode());
		pst1.addBatch();
	}

	private void writeLogIfPrividerExist(PreparedStatement pst1, String pk_vendor, String uapAccountID,
			String supplyRange, String operate) throws SQLException {
		pst1.setString(1, String.valueOf(UUIDLong.longUUID()));
		pst1.setString(2, pk_vendor);
		pst1.setString(3, uapAccountID);
		pst1.setString(4, supplyRange);
		pst1.setString(5, operate);
		pst1.setString(6, this.providerImportFormBean.getReason());
		pst1.setString(7, "OA供应商导入批准表");
		pst1.setString(8, this.providerImportFormBean.getNumber());
		pst1.setString(9, this.uapUserID);
		pst1.setString(10, MyUtil.getNowStr());
		pst1.setString(11, MyUtil.getTodayDateStr());
		pst1.setString(12, this.providerImportFormBean.getMemberCode());
		pst1.setString(13, uapAccountID);
		pst1.setString(14, supplyRange);
		pst1.setString(15, pk_vendor);
		pst1.addBatch();
	}

	public boolean setUapAccountList() {
		log.info("getcompanyList().size():" + this.providerImportFormBean.getcompanyList().size());
		this.companyList = this.providerImportFormBean.getcompanyList();
		return (this.companyList != null) && (this.companyList.size() > 0);
	}

	private SrmSupplyTypeBean typeIsExist(String pk_corp, String pk_invclass, List<SrmSupplyTypeBean> supplyTypeBeans) {
		if (supplyTypeBeans != null) {
			int i = 0;
			for (int size = supplyTypeBeans.size(); i < size; i++) {
				if ((supplyTypeBeans.get(i) != null)
						&& (pk_corp.equals(((SrmSupplyTypeBean) supplyTypeBeans.get(i)).getPk_corp()))
						&& (pk_invclass.equals(((SrmSupplyTypeBean) supplyTypeBeans.get(i)).getPk_invclass()))) {
					return (SrmSupplyTypeBean) supplyTypeBeans.get(i);
				}
			}
		}
		return null;
	}

	public boolean isWriteToErpSuccess() {
		return this.writeToErpSuccess;
	}
}
